home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _01F2C456C5CB469F93E1D98BEB2D697F < prev    next >
Encoding:
Text File  |  2004-01-06  |  9.9 KB  |  194 lines

  1. -------------------------------------------------------------------------
  2. --    Menu Script Code
  3. --
  4. --    Created by Lennert Schneider
  5. --
  6. -- Copyright (C) 2001 Crytek Studios Inc.
  7. -------------------------------------------------------------------------
  8.  
  9.  
  10. --Menu Definition
  11. ------------------------------------------------------------------------
  12.  
  13. CmdGui={
  14.     nMenuId=0,
  15.     nCmdPage=0,
  16.     pStdMouseCursor=0,
  17.     nStdCursorSize=20,
  18.     pMouseCursor=0,
  19.     nCursorSize=0,
  20.     nCursorOfsX=0,
  21.     nCursorOfsY=0,
  22.     nMouseX=0,
  23.   nMouseY=0,
  24.     nMouseState=0,
  25.     pData=nil,
  26.     pPlayerButtons={},
  27. }
  28.  
  29. -------------------------------------------------------------------------
  30. --Menu
  31. -------------------------------------------------------------------------
  32. function CmdGui:OnInit(nMenuId)
  33.     Game:SetMenuCallback(nMenuId, "CmdGuiMenuCallback");
  34.     --load mouse cursor image
  35.     CmdGui.pStdMouseCursor=System:LoadImage("textures/GUI/mousecursor.tga");
  36.     CmdGui.pMouseCursor=CmdGui.pStdMouseCursor;
  37.     CmdGui.nCursorSize=CmdGui.nStdCursorSize;
  38.     --create controls & stuff
  39.     local CmdPage=Game:CreateMenuPage(nMenuId, "CmdPage");
  40.     
  41.     CmdGui.nMenuId=nMenuId;
  42.     CmdGui.nCmdPage=CmdPage;
  43.     
  44.     CmdGui.MoveMapBtn=Game:AddButton(nMenuId, CmdPage,"MOVEMAP",nil,"GUI/cmd_move_n","GUI/cmd_move_o",370-32,590-32,32,32,"NOTHING",format( "Shift"));
  45.     CmdGui.ZoomInMapBtn=Game:AddButton(nMenuId, CmdPage,"ZOOMINMAP",nil,"GUI/cmd_ZoomIn_n","GUI/cmd_ZoomIn_o",410-32,590-32,32,32,"NOTHING",format( "Zoom In"));
  46.     CmdGui.ZoomOutMapBtn=Game:AddButton(nMenuId, CmdPage,"ZOOMOUTMAP",nil,"GUI/cmd_ZoomOut_n","GUI/cmd_ZoomOut_o",450-32,590-32,32,32,"NOTHING",format( "Zoom Out"));
  47.     CmdGui.ZoomRangeMapBtn=Game:AddButton(nMenuId, CmdPage,"ZOOMRANGEMAP",nil,"GUI/cmd_ZoomRange_n","GUI/cmd_ZoomRange_o",490-32,590-32,32,32,"NOTHING",format( "Zoom Range"));
  48.     
  49.     CmdGui.Cam1OnBtn=Game:AddButton(nMenuId, CmdPage,"CAM1ON",nil,"GUI/cmd_camactivate_n","GUI/cmd_camactivate_o",520,170,32,32,"NOTHING",format( "Enable Camera 1"));
  50.     CmdGui.Cam1OffBtn=Game:AddButton(nMenuId, CmdPage,"CAM1OFF",nil,"GUI/cmd_camdeactivate_n","GUI/cmd_camdeactivate_o",555,170,32,32,"NOTHING",format( "Disable Camera 1"));
  51.     CmdGui.Cam1FreezeBtn=Game:AddButton(nMenuId, CmdPage,"CAM1FREEZE",nil,"GUI/cmd_camfreeze_n","GUI/cmd_camfreeze_o",590,170,32,32,"NOTHING",format( "Freeze Camera 1"));
  52.     
  53.     CmdGui.Cam2OnBtn=Game:AddButton(nMenuId, CmdPage,"CAM2ON",nil,"GUI/cmd_camactivate_n","GUI/cmd_camactivate_o",520,390,32,32,"NOTHING",format( "Enable Camera 2"));
  54.     CmdGui.Cam2OffBtn=Game:AddButton(nMenuId, CmdPage,"CAM2OFF",nil,"GUI/cmd_camdeactivate_n","GUI/cmd_camdeactivate_o",555,390,32,32,"NOTHING",format( "Disable Camera 2"));
  55.     CmdGui.Cam2FreezeBtn=Game:AddButton(nMenuId, CmdPage,"CAM2FREEZE",nil,"GUI/cmd_camfreeze_n","GUI/cmd_camfreeze_o",590,390,32,32,"NOTHING",format( "Freeze Camera 2"));
  56.     
  57.     local Orders1=Game:AddButton(nMenuId, CmdPage,"CMDB1",Language.Orders1,nil,nil,10,80,15,15,"NOTHING",format( "Pulldown menu for [Primary Orders]"));
  58.     Game:SetButtonFont(nMenuId, CmdPage,Orders1,"Default","CmdGui",1,1,1);
  59.     
  60.     local Orders2=Game:AddButton(nMenuId, CmdPage,"CMDB2",Language.Orders2,nil,nil,180,80,15,15,"NOTHING",format( "Pulldown menu for [Secondary Orders]"));
  61.     Game:SetButtonFont(nMenuId, CmdPage,Orders2,"Default","CmdGui",1,1,1);
  62.     
  63.     local Special=Game:AddButton(nMenuId, CmdPage,"CMDB3",Language.Special,nil,nil,370,80,15,15,"NOTHING",format( "Pulldown menu for [Special Orders]"));
  64.     Game:SetButtonFont(nMenuId, CmdPage,Special,"Default","CmdGui",1,1,1);
  65.     
  66.     local PDMenu;
  67.     CmdGui.O1_Go=Game:AddButton(nMenuId, CmdPage,"PD1B1",Language.O1_Go,nil,nil,0,0,16,16,"NOTHING",format( "Go to destination-point"));
  68.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.O1_Go,"Default","CmdGui",1,1,1);
  69.     CmdGui.O1_Attack=Game:AddButton(nMenuId, CmdPage,"PD1B2",Language.O1_Attack,nil,nil,0,0,16,16,"NOTHING",format( "Attack destination-point"));
  70.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.O1_Attack,"Default","CmdGui",1,1,1);
  71.     CmdGui.O1_Defend=Game:AddButton(nMenuId, CmdPage,"PD1B3",Language.O1_Defend,nil,nil,0,0,16,16,"NOTHING",format( "Defend destination-point"));
  72.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.O1_Follow,"Default","CmdGui",1,1,1);
  73.     PDMenu=Game:InitPDMenu(nMenuId, CmdPage, Orders1);
  74.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.O1_Go);
  75.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.O1_Attack);
  76.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.O1_Defend);
  77.     
  78.     CmdGui.O2_Cover=Game:AddButton(nMenuId, CmdPage,"PD2B1",Language.O2_Cover,nil,nil,0,0,16,16,"NOTHING",format( "Cover the destination-point"));
  79.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.O2_Cover,"Default","CmdGui",1,1,1);
  80.     CmdGui.O2_BarrageFire=Game:AddButton(nMenuId, CmdPage,"PD2B2",Language.O2_BarrageFire,nil,nil,0,0,16,16,"NOTHING",format( "Perform a barrage-fire at the destination-point"));
  81.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.O2_BarrageFire,"Default","CmdGui",1,1,1);
  82.     PDMenu=Game:InitPDMenu(nMenuId, CmdPage, Orders2);
  83.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.O2_Cover);
  84.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.O2_BarrageFire);
  85.     
  86.     CmdGui.S_Grenade=Game:AddButton(nMenuId, CmdPage,"PD3B1",Language.S_Grenade,nil,nil,0,0,16,16,"NOTHING",format( "Throw a grenade at the destination-point"));
  87.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.S_Grenade,"Default","CmdGui",1,1,1);
  88.     CmdGui.S_BlendGrenade=Game:AddButton(nMenuId, CmdPage,"PD3B2",Language.S_BlendGrenade,nil,nil,0,0,16,16,"NOTHING",format( "Throw a blend-grenade at the destination-point"));
  89.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.S_BlendGrenade,"Default","CmdGui",1,1,1);
  90.     CmdGui.S_SmokeGrenade=Game:AddButton(nMenuId, CmdPage,"PD3B3",Language.S_SmokeGrenade,nil,nil,0,0,16,16,"NOTHING",format( "Throw a smoke-grenade at the destination-point"));
  91.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.S_SmokeGrenade,"Default","CmdGui",1,1,1);
  92.     CmdGui.S_Trap=Game:AddButton(nMenuId, CmdPage,"PD3B4",Language.S_Trap,nil,nil,0,0,16,16,"NOTHING",format( "Set a trap at the destination-point"));
  93.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.S_Trap,"Default","CmdGui",1,1,1);
  94.     CmdGui.S_NoFire=Game:AddButton(nMenuId, CmdPage,"PD3B5",Language.S_NoFire,nil,nil,0,0,16,16,"NOTHING",format( "Don't fire"));
  95.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.S_NoFire,"Default","CmdGui",1,1,1);
  96.     CmdGui.S_Loud=Game:AddButton(nMenuId, CmdPage,"PD3B6",Language.S_Loud,nil,nil,0,0,16,16,"NOTHING",format( "Go loud"));
  97.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.S_Loud,"Default","CmdGui",1,1,1);
  98.     CmdGui.S_Silent=Game:AddButton(nMenuId, CmdPage,"PD3B7",Language.S_Silent,nil,nil,0,0,16,16,"NOTHING",format( "Go silent"));
  99.     Game:SetButtonFont(nMenuId, CmdPage,CmdGui.S_Silent,"Default","CmdGui",1,1,1);
  100.     
  101.     PDMenu=Game:InitPDMenu(nMenuId, CmdPage, Special);
  102.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.S_Grenade);
  103.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.S_BlendGrenade);
  104.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.S_SmokeGrenade);
  105.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.S_Trap);
  106.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.S_NoFire);
  107.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.S_Loud);
  108.     Game:AddPDMenuItem(nMenuId, CmdPage, PDMenu, CmdGui.S_Silent);
  109.     
  110.     for y=0,3,1 do
  111.         for x=0,3,1 do
  112.             CmdGui.pPlayerButtons[y*4+x+1]=Game:AddButton(nMenuId, CmdPage, "PB"..x..y, "", nil, nil, 0, 0, 15, 15, "NOTHING", "Unit selector/status");
  113.             Game:SetButtonFont(nMenuId, CmdPage, CmdGui.pPlayerButtons[y*4+x+1], "Default", "CmdGui", 1, 1, 1);
  114.             Game:SetButtonPosition(nMenuId, CmdPage, CmdGui.pPlayerButtons[y*4+x+1], 30+192.5+x*192.5, 2+y*20, 15, 15, 2);
  115.         end
  116.     end
  117.  
  118.     Game:SetCurrentPage(nMenuId, "CmdPage");
  119. end
  120.  
  121. -------------------------------------------------------------------------
  122. function CmdGui:OnDraw(nMouseX,nMouseY,nMouseState,pData)
  123.     CmdGui.nMouseX=nMouseX;
  124.     CmdGui.nMouseY=nMouseY;
  125.     CmdGui.nMouseState=nMouseState;
  126.     CmdGui.pData=pData;
  127.     System:DrawImage(CmdGui.pMouseCursor,CmdGui.nMouseX-CmdGui.nCursorOfsX, CmdGui.nMouseY-CmdGui.nCursorOfsY, CmdGui.nCursorSize, CmdGui.nCursorSize, 4);
  128. end
  129.  
  130. -------------------------------------------------------------------------
  131. function CmdGui:OnShutdown()
  132. end
  133.  
  134. -------------------------------------------------------------------------
  135. -------------------------------------------------------------------------
  136. CmdGuiMenuCallback={
  137. }
  138.  
  139. -------------------------------------------------------------------------
  140. function CmdGuiMenuCallback:OnMenuItemClick(tbl)
  141.     System:LogToConsole("MNU => ID: "..tbl.id.." (X: "..tbl.x..", Y: "..tbl.y..")");
  142.     if ( tbl.id == CmdGui.O1_Go ) then
  143.         Hud.nLastCmd=CMD_GO;
  144.         Hud.SetMode(Hud, MODE_TARGETHIT);
  145.     end
  146.     if ( tbl.id == CmdGui.O1_Attack ) then
  147.         Hud.nLastCmd=CMD_ATTACK;
  148.         Hud.SetMode(Hud, MODE_TARGETHIT);
  149.     end
  150.     if ( tbl.id == CmdGui.O1_Defend ) then
  151.         Hud.nLastCmd=CMD_DEFEND;
  152.         Hud.SetMode(Hud, MODE_TARGETHIT);
  153.     end
  154.     if ( tbl.id == CmdGui.O2_Cover ) then
  155.         Hud.nLastCmd=CMD_COVER;
  156.         Hud.SetMode(Hud, MODE_TARGETHIT);
  157.     end
  158.     if ( tbl.id == CmdGui.O2_BarrageFire ) then
  159.         Hud.nLastCmd=CMD_BARRAGEFIRE;
  160.         Hud.SetMode(Hud, MODE_TARGETHIT);
  161.     end
  162. end
  163.  
  164. -------------------------------------------------------------------------
  165. function CmdGuiMenuCallback:OnButtonClick(tbl)
  166.     if (tbl.id==CmdGui.MoveMapBtn) then
  167.         Hud.SetMode(Hud, MODE_PAN);
  168.     elseif (tbl.id==CmdGui.ZoomInMapBtn) then
  169.         Hud.fZoom=Hud.fZoom*1.2;
  170.         if (Hud.fZoom>Hud.fMaxZoom) then
  171.             Hud.fZoom=Hud.fMaxZoom;
  172.         end
  173.     elseif (tbl.id==CmdGui.ZoomOutMapBtn) then
  174.         Hud.fZoom=Hud.fZoom*0.8;
  175.         if (Hud.fZoom<1) then
  176.             Hud.fZoom=1;
  177.         end
  178.     elseif (tbl.id==CmdGui.ZoomRangeMapBtn) then
  179.         Hud.SetMode(Hud, MODE_SELRANGE);
  180.     elseif (tbl.id==CmdGui.Cam1OnBtn) then
  181.         if (Hud.pSingleSelection) then
  182.             Hud.pCam1=Hud.pSingleSelection;
  183.         end
  184.     elseif (tbl.id==CmdGui.Cam1OffBtn) then
  185.         Hud.pCam1=nil;
  186.     elseif (tbl.id==CmdGui.Cam2OnBtn) then
  187.         if (Hud.pSingleSelection) then
  188.             Hud.pCam2=Hud.pSingleSelection;
  189.         end
  190.     elseif (tbl.id==CmdGui.Cam2OffBtn) then
  191.         Hud.pCam2=nil;
  192.     end
  193. --    System.LogToConsole("BTN => ID: "..tbl.id.." (X: "..tbl.x..", Y: "..tbl.y..")");
  194. end